#set(seoTitle="登录 JFinal 社区")
#@layout()
#define main()
<!-- 内容容器 -->
<div class="jf-panel-box jf-pull-left">
	<!-- 登录 -->
	<div class="jf-panel jf-reg-box">
		<div class="jf-reg-panel">
			<h2 class="jf-reg-panel-name">登&nbsp;&nbsp;录</h2>
			<div class="jf-reg-panel-content">
				<form id="login_form" action="/login/doLogin?returnUrl=#(returnUrl)" method="post">
					<table class="jf-reg-table">
						<tr>
							<th>账号</th>
							<td>
								<input type="text" name="userName" class="TEXT" placeholder="请输入邮箱">
								<span id="userNameMsg"></span>
							</td>
						</tr>
						<tr>
							<th>密码</th>
							<td>
								<input type="password" name="password" class="TEXT">
								<span id="passwordMsg"></span>
							</td>
						</tr>
						<tr>
							<th><img title="点击刷新" class="captcha" src="/login/captcha" onclick="updateCaptcha();"></th>
							<td>
								<input type="text" name="captcha" class="TEXT" id="captchaInput">
								<span id="captchaMsg"></span>
							</td>
						</tr>
						<tr>
							<th>&nbsp;</th>
							<td>
								<input type='checkbox' id="keepLogin" name='keepLogin' value='1' checked='checked'/>&nbsp;
								<label for="keepLogin" style="cursor: pointer;">下次自动登录</label>
							</td>
						</tr>
						<tr>
							<th>&nbsp;</th>
							<td>
								<input type="submit" class="SUBMIT" value="登 录">
							</td>
						</tr>
						<tr>
							<!--<th>&nbsp;</th>-->
							<td class="jump-link" colspan="2">
								没有账号:&nbsp;<a href="/reg" onclick="appendReturnUrl(this)">现在注册</a>
								<a href="/login/forgetPassword">忘记密码</a>&nbsp;
								<a href="/reg/notActivated">还没激活</a>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>

</div>

<!-- 包含侧边栏文件 -->
<!-- include "_sidebar.html" / -->
#end

#define js()
	<script type="text/javascript" src="/assets/jquery_form/jquery.form.min.js"></script>
	<script type="text/javascript" src="/assets/layer/layer/layer.js"></script>

	<script type="text/javascript">
		$(document).ready(function() {
			$("#login_form").ajaxForm({
				dataType: "json"
				, beforeSubmit: function(formData, jqForm, options) {       // 表单提交之前回调
					$(".jf-reg-table td span").text("");                                    // 清空所有验证 msg
				}
				, success: function(ret) {
					// 业务层验证成功
					if(ret.state == "ok") {
						location.href = ret.returnUrl;
						return ;
					}
					
					// 业务层验证失败
					if (ret.state == "fail") {
						layer.msg(ret.msg, {
									shift: 6
									, shade: 0.3
									, time: 2500
									, offset: "165px"
									, closeBtn: 1
									, shadeClose: true
								} , function() {
									updateCaptcha();
								}
						);
						return ;
					}
					
					// Validator 层验证失败
					if (ret.userNameMsg) {
						$("#userNameMsg").text(ret.userNameMsg);
					}
					if (ret.passwordMsg) {
						$("#passwordMsg").text(ret.passwordMsg);
					}
					if (ret.captchaMsg) {
						updateCaptcha();    // captcha 被验证过以后会立即失效，更新之
						$("#captchaMsg").text(ret.captchaMsg);
					}
				}
				, error: function(ret) { }              // ret.status != 200 时回调
				, complete: function(ret) { }       // 无论是 success 还是 error，最终都会被回调
			});
		});

		function updateCaptcha() {
			$(".captcha").attr("src", "/login/captcha?v=" + Math.random());
			$("#captchaInput").val("");
		}
	</script>
#end